<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html; charset=UTF-8" %>
<html>
<head>
    <title>文件分享列表</title>

</head>
<body class="container">
<div>
    <div>
        <form action="" id="fm">
            <div>
                <div>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <!-- <button type="button" class="btn btn-default" onclick="download()">下载</button> -->
                    <button type="button" class="btn btn-default" onclick="delFile()">删除</button>
                </div>
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th><input type="checkbox" onclick="selectAll()"
                                   id="SelectAll"/></th>
                        <th>编号</th>
                        <th>名称</th>
                        <th>时间</th>
                        <th>密码</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="diskFile" items="${diskFileList}"
                               varStatus="status">
                        <tr>
                            <td><input type="checkbox" class="checkItem"/></td>
                            <td>${status.index+1 }</td>
                            <td>${diskFile.fileName }</td>
                            <td>${diskFile.uploadDate }</td>
                            <td>${diskFile.downloadPwd }</td>
                            <td style="display: none">${diskFile.uuid }</td>
                            <td>
                                <button type="button" value="${diskFile.uuid}" class="btn btn-info btn-xs"
                                        onclick="downloadShareFile(this.value)">下载
                                </button>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </form>
    </div>
    <div>
        <div>
            <button class="btn btn-primary btn-lg" data-toggle="modal"
                    data-target="#myModal" id="shareFileClick" style="display: none;">开始演示模态框
            </button>
            <!-- 模态框（Modal） -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"
                                    aria-hidden="true">&times;
                            </button>
                            <h4 class="modal-title" id="myModalLabel"
                                style="text-align: center;">下载分享文件</h4>
                        </div>
                        <form action="/disktalk/file/shareJudge" style="text-align: center;"
                              method="post">
                            <div class="modal-body" style="margin: auto;">
                                请输入密码:<input type="text" name="pwd" placeholder="请输入6位数的分享密码..."/>
                            </div>
                            <div class="modal-body" style="display: none">
                                密码:<input type="text" name="password"/>
                            </div>
                            <div class="modal-body" style="display: none">
                                UUID:<input type="text" name="ids"/>
                            </div>

                            <div class="modal-footer"
                                 style="margin: 0 auto; text-align: center;">
                                <button type="button" class="btn btn-default"
                                        data-dismiss="modal" name="close">关闭
                                </button>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" class="btn btn-primary" onclick="shareDownLoad()">提取</button>
                            </div>
                        </form>

                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal -->
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    window.onload = searchFile;
    function searchFile() {
        $("ul li:eq(2)").addClass("active");
    }
    function downloadShareFile(ids) {
        $("#shareFileClick").click();
        $("input[name='ids']").val(ids);
    }

    function shareDownLoad() {
        var uuid = $("input[name='ids']").val();
        var password = $("input[name='pwd']").val();
        $.ajax({
            url: '/disktalk/file/shareJudge',
            method: 'post',
            data: {
                ids: uuid,
                pwd: password
            },
            success: function (result) {
                var info = eval('(' + result + ')');
                if (!info.result) {
                    alert("提取的密码有误！！！");
                } else {
                    window.location.href = '/disktalk/file/download?ids=' + uuid;
                    $("button[name='close']").click();
                }
            }
        });
    }
</script>
</body>
</html>
